package com.hhf.rpa.engine.service.impl;

import com.hhf.rpa.engine.model.ScriptExecConfigurer;
import com.hhf.rpa.handler.ScriptHandler;
import com.hhf.rpa.engine.service.ScriptExecutor;
import com.hhf.rpa.glue.GlueTypeEnum;
import com.hhf.rpa.glue.HandlerFactory;
import com.hhf.rpa.glue.HandlerParam;
import org.springframework.stereotype.Service;

@Service
public class ScriptEngineDependencyInterfaceExecutor implements ScriptExecutor {

    public Object execScript(ScriptExecConfigurer configurer) {
        String glueType = configurer.getGlueType();
        HandlerParam handlerParam = new HandlerParam();
        handlerParam.setGlueTypeEnum(GlueTypeEnum.match(glueType));
        handlerParam.setGlueCode(configurer.getGlueCode());
        handlerParam.setBeanName(configurer.getBeanName());
        ScriptHandler scriptHandler = (ScriptHandler) HandlerFactory.getInstance().build(handlerParam);
        System.setProperty("java.awt.headless", "false");
        return scriptHandler.exec(configurer.getParams());
    }
}
